﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImobitechModel.com.Command;
using ImobitechDao;
using ImobitechModel.Facade;
using ImobitechModel.com.Constantes;

namespace ImobitechModel.com.Controller
{
    public class ControladorPlan
    {
        public Object retornaPlanos(IDictionary<string, string> values)
        {
            Plan plan = new Plan();


            AnuncioFacade anuncioFacade = AnuncioFacade.getInstance();
            return anuncioFacade.retornaPlanos();
            //List<Plan> planos = (List<Plan>)anuncioFacade.retornaPlanos();

            //List<Dictionary<string, string>> planDictionary = new List<Dictionary<string, string>>();
            //planDictionary.Add(NomeCampoConstantes.campo_planName, plano.Name);
            //planDictionary.Add(NomeCampoConstantes.campo_planValue, plano.Value.ToString());
            //planDictionary.Add(NomeCampoConstantes.campo_planDateStart, plano.Date_Start.ToString("dd/MM/yyyy"));
            //planDictionary.Add(NomeCampoConstantes.campo_planDateFinish, plano.Date_Finish.ToString("dd/MM/yyyy"));
        }

        public Object retornaPlano(IDictionary<string, string> values)
        {
            Plan plan = new Plan();
            int id = int.Parse(values.First(p => p.Key == NomeCampoConstantes.campo_planId).Value);
            AnuncioFacade anuncioFacade = AnuncioFacade.getInstance();
            Plan plano = (Plan)anuncioFacade.retornaPlano(id);

            IDictionary<string, string> planDictionary = new Dictionary<string, string>();
            planDictionary.Add(NomeCampoConstantes.campo_planName, plano.Name);
            planDictionary.Add(NomeCampoConstantes.campo_planValue, plano.Value.ToString());
            planDictionary.Add(NomeCampoConstantes.campo_planDateStart, plano.Date_Start.ToString("dd/MM/yyyy"));
            planDictionary.Add(NomeCampoConstantes.campo_planDateFinish, plano.Date_Finish.ToString("dd/MM/yyyy"));

            return planDictionary;
        }

        public Object insertPlan(IDictionary<string, string> values)
        {
            Plan plan = new Plan();
            plan.Name = values.First(p => p.Key == NomeCampoConstantes.campo_planName).Value;
            double receber = 0;
            double.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planValue).Value, out receber);
            plan.Value = receber;

            DateTime data = new DateTime();
            DateTime.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planDateStart).Value, out data);
            plan.Date_Start = data;
            DateTime.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planDateFinish).Value, out data);
            plan.Date_Finish = data;

            AnuncioFacade planFacade = AnuncioFacade.getInstance();
            return planFacade.insertPlan(plan);
        }

        public Object editaPlan(IDictionary<string, string> values)
        {
            Plan plan = new Plan();
            plan.Name = values.First(p => p.Key == NomeCampoConstantes.campo_planName).Value;
            double receber = 0;
            double.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planValue).Value, out receber);
            plan.Value = receber;

            DateTime data = new DateTime();
            DateTime.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planDateStart).Value, out data);
            plan.Date_Start = data;
            DateTime.TryParse(values.First(p => p.Key == NomeCampoConstantes.campo_planDateFinish).Value, out data);
            plan.Date_Finish = data;
            plan.Id = int.Parse(values.First(p => p.Key == NomeCampoConstantes.campo_planId).Value);
            AnuncioFacade anuncioFacade = AnuncioFacade.getInstance();
            return anuncioFacade.editaPlan(plan);
        }
    }
}